package com.joolun.web.controller.promotion;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.joolun.system.domain.EduCourse;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.system.domain.EduLandWebsite;
import com.joolun.system.service.IEduLandWebsiteService;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 模板建站Controller
 * 
 * @author joolun
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/promotion/website")
public class EduLandWebsiteController extends BaseController
{
    @Autowired
    private IEduLandWebsiteService eduLandWebsiteService;

    /**
     * 查询模板建站列表
     */
    @GetMapping("/list")
    public TableDataInfo list(EduLandWebsite eduLandWebsite)
    {
        startPage();
        List<EduLandWebsite> list = eduLandWebsiteService.selectEduLandWebsiteList(eduLandWebsite);
        return getDataTable(list);
    }

    /**
     * 导出模板建站列表
     */
    @PreAuthorize("@ss.hasPermi('promotion:website:export')")
    @Log(title = "模板建站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduLandWebsite eduLandWebsite)
    {
        List<EduLandWebsite> list = eduLandWebsiteService.selectEduLandWebsiteList(eduLandWebsite);
        ExcelUtil<EduLandWebsite> util = new ExcelUtil<EduLandWebsite>(EduLandWebsite.class);
        util.exportExcel(response, list, "模板建站数据");
    }

    /**
     * 获取模板建站详细信息
     */
    @GetMapping(value = "/{landId}")
    public AjaxResult getInfo(@PathVariable("landId") Long landId)
    {
        return success(eduLandWebsiteService.selectEduLandWebsiteByLandId(landId));
    }

    /**
     * 新增模板建站
     */
    @PreAuthorize("@ss.hasPermi('promotion:website:add')")
    @Log(title = "模板建站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduLandWebsite eduLandWebsite)
    {
        eduLandWebsite.setCreateBy(getUsername());
        return toAjax(eduLandWebsiteService.insertEduLandWebsite(eduLandWebsite));
    }

    /**
     * 修改模板建站
     */
    @PreAuthorize("@ss.hasPermi('promotion:website:edit')")
    @Log(title = "模板建站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduLandWebsite eduLandWebsite)
    {
        eduLandWebsite.setCreateBy(getUsername());
        return toAjax(eduLandWebsiteService.updateEduLandWebsite(eduLandWebsite));
    }

    /**
     * 删除模板建站
     */
    @PreAuthorize("@ss.hasPermi('promotion:website:remove')")
    @Log(title = "模板建站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{landIds}")
    public AjaxResult remove(@PathVariable Long[] landIds)
    {
        return toAjax(eduLandWebsiteService.deleteEduLandWebsiteByLandIds(landIds));
    }

    /**
     * 根据id修改排序
     */
    @PreAuthorize("@ss.hasPermi('promotion:website:edit')")
    @Log(title = "模板建站", businessType = BusinessType.UPDATE)
    @GetMapping("/updateSort")
    public AjaxResult updateSort(Integer id,Integer landSort)
    {
        LambdaUpdateWrapper<EduLandWebsite> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(EduLandWebsite::getLandSort, landSort);
        wrapper.eq(EduLandWebsite::getLandId, id);
        return toAjax(eduLandWebsiteService.update(wrapper));
    }

    /**
     * 根据投放计划id联表查询
     */
    @GetMapping("/delivery/plan")
    public AjaxResult selectTouFangId(Long id)
    {
        return success(eduLandWebsiteService.selectTouFangId(id));
    }
}
